package com.doubao.msghadler;

import com.doubao.protocol.Msg;
import com.doubao.util.ChannelManage;
import io.netty.channel.Channel;


/**
 * 消息处理模板
 *
 * description:abstractMsgHandler
 * <p>
 * author:sult
 * time: 2018/11/2 10:53
 **/
public abstract  class AbstractMsgHandler {


    protected Msg msg;

    protected Channel fromChannel;

    public AbstractMsgHandler(Msg msg, Channel fromChannel) {
        this.msg = msg;
        this.fromChannel = fromChannel;
    }

    public Boolean sendMsg(){
        Boolean tag=false;
        if(toIsOnline()){
            tag=sendWebSoketMsg();
        }else{
            tag=sendWechatTplMsg();
        }
        return tag;
    }

    protected abstract Boolean sendWechatTplMsg();

    protected abstract Boolean sendWebSoketMsg();

    private boolean toIsOnline() {
        return ChannelManage.userIdAndChannelMap.get(msg.getTo())==null?false:true;
    }

}
